﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;

class CogScript : EnhancementBlock
{

    Rigidbody Rigidbody;
    ConfigurableJoint myJoint;
    AnimationCurve animationCurve;

    public override void SafeAwake()
    {
#if DEBUG
        Debug.Log("动力齿轮添加摇杆");
#endif
    }

    CogMotorControllerHinge cogMotorControllerHinge;
    public override void OnSimulateStart_EnhancementEnabled()
    {
        Rigidbody = GetComponent<Rigidbody>();
        myJoint = GetComponent<ConfigurableJoint>();
        cogMotorControllerHinge = GetComponent<CogMotorControllerHinge>();

       // animationCurve = new AnimationCurve(new Keyframe[] { new Keyframe(0f+joyAxis.Offset, 0f), new Keyframe(1f*joyAxis.Max, cogMotorControllerHinge.SpeedSlider.Value) });
    }

    public override void SimulateUpdateAlways_EnhancementEnable()
    {
        cogMotorControllerHinge.Input = joyAxis.Value_Direction;
    }
    float targetSpeed = 0f;
    public override void SimulateFixedUpdate_EnhancementEnabled()
    {

        if (Rigidbody.IsSleeping())
        {
            Rigidbody.WakeUp();
        }
        try
        {
            if (myJoint.connectedBody.IsSleeping())
            {
                myJoint.connectedBody.WakeUp();
            }
        }
        catch { }

        float value = 0f;
        if (LerpToggle.IsActive)
        {
            value = Mathf.MoveTowards(targetSpeed, animationCurve.Evaluate(Mathf.Abs(joyAxis.Value)), LerpSpeedSlider.Value * Time.deltaTime);
        }
        else
        {
            value = /*animationCurve.Evaluate(*/Mathf.Abs(joyAxis.Value)/*)*/;
        }

        targetSpeed = value;
        cogMotorControllerHinge.SpeedSlider.Value = targetSpeed;

    }

}

